package thirt.component
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	import mx.containers.Canvas;
	import mx.core.UIComponent;

	public class ColorBtn extends Canvas
	{
		private var ui:UIComponent;
		private var _color:uint;
		
		private var filt:GlowFilter;
		private var fade:Boolean;
		
		public function ColorBtn()
		{
			this.styleName = "colorBtn";
			ui = new UIComponent;
			this.addChild(ui);
			
			filt = new GlowFilter(0x1c9cf6,1,8,8);
			this.addEventListener(MouseEvent.ROLL_OVER,onOver);
			this.addEventListener(MouseEvent.ROLL_OUT,onOut);
		}
		public function set color(value:uint):void{
			this._color = value;
			ui.graphics.clear();
			ui.graphics.beginFill(value,1);
			ui.graphics.drawRect(14,8,16,16);
			ui.graphics.endFill();
		}
		public function get color():uint{
			return _color;
		}
		
		private function onOver(event:Event):void{
			fade = true;
			this.addEventListener(Event.ENTER_FRAME,onFrame);
		}
		private function onOut(event:Event):void{
			fade = false;
			this.addEventListener(Event.ENTER_FRAME,onFrame);
		}
		private function onFrame(event:Event):void{
			if(fade){
				if(filt.alpha <= 1){
					filt.alpha += 0.2;
				}else{
					this.removeEventListener(Event.ENTER_FRAME,onFrame);
				}
			}else{
				if(filt.alpha >= 0){
					filt.alpha -= 0.2;
				}else{
					this.removeEventListener(Event.ENTER_FRAME,onFrame);
				}
			}
			this.filters = [filt];
		}
		
	}
}